package com.qf.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class ReidsLockUtil {
    @Autowired
    private StringRedisTemplate redisTemplate;
    public boolean lock(String key,String vlue,int second){
        return redisTemplate.opsForValue().setIfAbsent(key,vlue,second, TimeUnit.SECONDS);
    }

    public void unlock(String key){
        redisTemplate.delete(key);
    }
}
